import numpy as np
def read_txt_split_by_space(path:str)->list[list[float]]:
    """读取txt文件，按空格分隔，返回一个二维浮点数列表
         param path: 文件名
         return: 二维浮点数列表
    """
    # read file
    data = open(path,'r+').readlines()
    # for each line
    for i in range(len(data)):
        # remove \n
        data[i] = data[i].replace('\n','')
        # remove empty string
        split_data = data[i].split(' ')
        # Make every string("1 2 3 4") become list([1 2 3 4])
        data[i] = split_data
    # to float list not become iterable list
    data = list([[float(x) for x in line] for line in data])
    # make it to be a numpy array
    data = np.array(data)
    # return a 2D float list as a result.
    return data
if __name__ == "__main__":
    data = read_txt_split_by_space(r'7-深度学习基本原理-三好学生案例\2.txt')
    print(data)

